﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DB_test.Models;

namespace DB_test
{
    class Program
    {
        private List<Diver> divers;

        public Program()
        {
        }

        public void Run()
        {
            MyDbConnection.SetConnectionString(@"Data Source=T002E004480\KBMSS;Initial Catalog=Diving;Integrated Security=True;MultipleActiveResultSets=True");

            divers = DiverMap.ReadDiversFromDatabase();
            PrintAllDivers();
            // RemoveAllDivers();
            //var diver = new Diver("Zac");
            //diver.AddJump(new Jump(32.0f, JumpTypes.Hard));
            //divers.Add(diver);



            DiverMap.SaveDiversToDatabase(divers);

            PrintAllDivers();
        }

        private void PrintAllDivers()
        {
            foreach (var diver in divers)
            {
                Console.WriteLine(diver.ToString());
                foreach (var jump in diver.Jumps)
                    Console.WriteLine(jump.ToString());
            }
        }

        private void RemoveAllDivers()
        {
            for(int i = divers.Count - 1; i >= 0; i--)
                RemoveDiver(divers[i]);
        }

        private void RemoveDiver(Diver diver)
        {
            divers.Remove(diver);
            DiverMap.RemoveDiver(diver);
        }

        static void Main(string[] args)
        {
            var program = new Program();
            program.Run();

        }
    }
}
